package com.lamer.console.base.service.impl;

import com.lamer.console.base.entity.Role;
import com.lamer.console.base.mapper.RoleMapper;
import com.lamer.console.base.service.IBaseService;
import com.lamer.console.base.service.IRoleService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author 黄诗鹏
 * @since 2021-11-09
 */
@Service("RoleServiceImpl")
public class RoleServiceImpl extends ServiceImpl<RoleMapper, Role> implements IRoleService, IBaseService {

    @Resource
    private RoleMapper roleMapper;

    @Override
    public boolean updateStatusById(int id) {
        Role role = roleMapper.selectById(id);
        int status = role.getStatus() == 1 ? 0 : 1;
        role.setStatus(status);
        int update = roleMapper.updateById(role);
        return update >= 1;
    }

    @Override
    public List<Role> getRoleListByUserId(int userId) {
        return roleMapper.selectListByUserId(userId);
    }
}
